<%@ page import="java.sql.Statement" import="java.sql.ResultSet" import="java.sql.Connection" %>
<%@page import="connection.DBConnection"%>
<%@page import="java.util.*" %>
<%@page import="java.text.SimpleDateFormat" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form>
<h2 align="center"> Customer Report</h2>
<table border=2 align="center">
<%  DBConnection dbc=new DBConnection();
			Connection con=dbc.getNewConnection();
			String selectedinv = (String) request.getAttribute("cin");
			String selectedname = (String) request.getAttribute("cname");
			String selectedcode = (String) request.getAttribute("ccd");
			String group = (String) request.getAttribute("grp");
			Statement st = null;
			ResultSet rs = null;
			 String inv="",newdate="",cd1="";
			 double adj=0.0,amt1=0.0,tot1=0.0;
			 int cred=0,cred1=0;
			 %>
			 <tr><th colspan=4 align=center><%=selectedname %></th></tr>
<tr>
		<td>Date </td>
		<td>Due date</td>
    	<td>Reference number</td>
    	<td>Amount </td>
    	</tr>

		
			 
			 
			 <%
			 



SimpleDateFormat sim = new SimpleDateFormat("dd-MM-yyyy");

Calendar calendar = Calendar.getInstance();
SimpleDateFormat fromsql = new SimpleDateFormat("yyyy-MM-dd");

try
{
   st=con.createStatement() ;
   

       		   rs=st.executeQuery("select date,innum,adjamount,balance,scred from salesinvoiceoutstanding where svname='"+selectedname+"' and ccode='"+selectedcode+"' group by innum");
	        	//rs=st.executeQuery("select date,");
	         while(rs.next()){ 
	        	 String dt=rs.getString(1);
	        	 String in=rs.getString(2);
	        	double amt=rs.getDouble(3);
	        	double am=rs.getDouble(4);
	        	 cred=rs.getInt(5);
	        	tot1=tot1+am;
	        amt1=amt1+amt;
	         newdate =sim.format(fromsql.parse(dt));
	        
	        calendar.setTime(sim.parse(newdate));
	       calendar.add(Calendar.DATE,cred); 
	       String due = sim.format(calendar.getTime());
	         %>
	         <tr>
	         <td><%=newdate%></td>
	         <td><%=due %></td>
	         <td><%=in%></td>
	         
	         <td><%=am %></td>
	         </tr>

        
  
	 		<%
	 		} }
			catch(Exception e){} %>
			
			
			
<tr><td></td><td></td><td>Total</td><td><%=tot1 %></td></tr>
</table>
<br>
<center><input type="button" value="Print this page" onClick="window.print()"></center>


</form>
</body>
</html>